package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/order")
@Slf4j
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @GetMapping("/conditionSearch")
    @ApiOperation("分页查询订单")
    public Result query(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = ordersService.page(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("statistics")
    @ApiOperation("条件查询订单")
    public Result count() {
        OrderStatisticsVO orderStatisticsVO = ordersService.count();
        return Result.success(orderStatisticsVO);
    }
    @PutMapping("rejection")
    @ApiOperation("拒单")
    public Result update (@RequestBody OrdersRejectionDTO ordersRejectionDTO){
       ordersService.update(ordersRejectionDTO);
       return Result.success();

    }
    @PutMapping("confirm")
    @ApiOperation("接单")
    public Result add (@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        ordersService.pas(ordersConfirmDTO);
        return Result.success();
    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result statusDele(@RequestBody OrdersCancelDTO ordersCancelDTO){
     ordersService.statusDele(ordersCancelDTO);
     return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result statusCome(@PathVariable Integer id){
        ordersService.statusCome(id);
        return Result.success();
    }
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result statusComplete(@PathVariable Integer id){
        ordersService.statusComplete(id);
        return Result.success();
    }

    @GetMapping("/details/{id}")
    @ApiOperation("订单详情")
    public Result <OrderVO> details (@PathVariable Long id) {
        OrderVO orderVO = ordersService.details(id);
        return Result.success(orderVO);
    }

}
